import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';

export default {
  //根据账套查询启用且未被关联的成本中心列表
  getCostCenterListBySobId(params) {
    // let params = {
    //   setOfBooksId
    // }
    return new Promise((resolve, reject) => {
      httpFetch.get(config.baseUrl + '/api/cost/center/group/category/search/costCenters', params)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //创建成本中心组类别
  createCostCenterGroupClass(obj) {
    // let obj = {
    //   "name": "catagory12",
    //   "code": "category1",
    //   "description": "create cost center group category",
    //   "tenantId": "943460749499830273",
    //   "setOfBooksId": "971996878340702210",
    //   "costCenterId": "4223",
    //   "enabled": true //启用状态
    // }
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/api/cost/center/group/category', obj)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //更新成本中心组类别
  updateCostCenterGroupClass(obj) {
    // let obj = {
    //   "id": "1070572900841873409",
    //   "name": "catagory12",
    //   "code": "category1",
    //   "description": "create cost center group category",
    //   "tenantId": "943460749499830273",
    //   "setOfBooksId": "971996878340702210",
    //   "costCenterId": "4223",
    //   "enabled": true //启用状态
    // }
    return new Promise((resolve, reject) => {
      httpFetch.put(config.baseUrl + '/api/cost/center/group/category', obj)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //成本中心组类别查询（列表）
  getCostCenterGroupClassList(params) {
    // let params = {
    //   setOfBooksId,
    //   costCenterGroupCategoryCode,
    //   costCenterGroupCategoryName,
    //   page,
    //   size
    // }
    return new Promise((resolve, reject) => {
      httpFetch.get(config.baseUrl + '/api/cost/center/group/category/list', params)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
  //成本中心组类别查询（单个详情）
  getCostCenterGroupClassDetail(params) {
    // let params = {
    //   id
    // }
    return new Promise((resolve, reject) => {
      httpFetch.get(config.baseUrl + '/api/cost/center/group/category/one', params)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },

  //获取账套列表
  getSetOfBooks() {
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/setOfBooks/by/tenant`)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },

  //根据成本中心组类别id获取下面的成本中心组
  getCostCenterGroupListByClassId(params) {
    // let params = {
    //   costCenterGroupCategoryId
    // }
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/cost/center/group/list`, params)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err);
        })
    })
  },
}
